package com.yuhs.zixing.study.multithread.mashibing.t001base.t005.status;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * Function: 线程状态
 *
 * @Author yuhongsheng
 * @Date: 2023-12-20 21:25:55
 */
@Slf4j
public class ThreadStatus003TimedWaiting {

    public static void main(String[] args) {

        Thread thread1 = new Thread(ThreadStatus003TimedWaiting::run1);
        thread1.start();
        for (; ; ) {
            Thread.State state = thread1.getState();
            if (!state.equals(Thread.State.TERMINATED)) {
                log.atInfo().log("线程状态thread1 {} ", state);
            }
        }


    }


    @SneakyThrows
    private static void run1() {
        for (int i = 0; i < 10; i++) {
            if (i % 2 != 0) {
                TimeUnit.SECONDS.sleep(1);
            }
        }
    }


}
